package view;

import java.awt.Dimension;
import java.beans.PropertyVetoException;
import java.util.Vector;

import javax.swing.BorderFactory;

import control.Controlador;
import control.ControladorMatricula;
import model.Aluno;
import model.Matricula;
import model.Turma;
import model.dao.AlunoDAO;
import model.dao.TurmaDAO;
import patterns.Bean;
import util.Constantes;
import util.Detalhar;
import util.components.buttons.JButtonCancelar;
import util.components.buttons.JButtonOK;

public class JanelaMatricula extends javax.swing.JInternalFrame implements Bean{

	private Matricula bean;
	private Controlador control;
	Vector turmas = null, alunos = null;
	public int tipoJanela;
	
	public JanelaMatricula(String title, Vector alunos, Vector turmas){
		super(title);
		control = new ControladorMatricula(this);
		this.turmas = new Vector(turmas);
		this.alunos = new Vector(alunos);
		initComponents();
		control.registraEventos();		
	}

	public void initComponents(){

		java.awt.GridBagConstraints gridBagConstraints;

		panelDadosTurma = new javax.swing.JPanel();
		panelDadosAluno = new javax.swing.JPanel();
		panelBotao = new javax.swing.JPanel();
		comboTurma = new javax.swing.JComboBox(turmas);
		comboAluno = new javax.swing.JComboBox(alunos);
		btnOk = new JButtonOK(control, "Ok");
		btnCancelar = new JButtonCancelar(this, "Cancelar");

		setLayout(new java.awt.GridBagLayout());

		panelDadosTurma.setBorder(BorderFactory.createTitledBorder("Turma"));
		panelDadosAluno.setBorder(BorderFactory.createTitledBorder("Aluno"));

		comboTurma.setPreferredSize(new Dimension(350, 20));
		comboAluno.setPreferredSize(new Dimension(350, 20));

		panelDadosTurma.add(comboTurma);
		panelDadosAluno.add(comboAluno);

		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		gridBagConstraints.weightx = 100.0;
		getContentPane().add(panelDadosTurma, gridBagConstraints);

		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		gridBagConstraints.weightx = 100.0;
		getContentPane().add(panelDadosAluno, gridBagConstraints);

		panelBotao.add(btnOk);
		panelBotao.add(btnCancelar);

		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		gridBagConstraints.weightx = 100.0;
		getContentPane().add(panelBotao, gridBagConstraints);	

		setVisible(true);
		setClosable(true);
		setResizable(true);
		setSize(new Dimension(390, 200));
		setLocation(200, 89);
	}

	private javax.swing.JPanel panelDadosTurma;
	private javax.swing.JPanel panelDadosAluno;
	private javax.swing.JPanel panelBotao;
	private javax.swing.JComboBox comboTurma;
	private javax.swing.JComboBox comboAluno;
	private javax.swing.JButton btnOk;
	private javax.swing.JButton btnCancelar;

	public void detalhar(){
		
	}
	
	public void desdetalhar(){
		
	}
	
	public Object getBean() {
		Aluno aluno = (Aluno) comboAluno.getSelectedItem();
		Turma turma = (Turma) comboTurma.getSelectedItem();

		if(aluno != null && turma != null){
			bean = new Matricula(aluno.getCodigoAluno(), turma.getCodTurma());
			if(bean != null)
				return bean;
		}

		return null;
	}

	public void setBean(Object bean) {

	}
	
	public int getTipoJanela() {
		return tipoJanela;
	}

	public void setTipoJanela(int tipoJanela) {
		this.tipoJanela = tipoJanela;
	}

	public javax.swing.JComboBox getComboTurma() {
		return comboTurma;
	}

	public javax.swing.JComboBox getComboAluno() {
		return comboAluno;
	}

	public javax.swing.JButton getBtnOk() {
		return btnOk;
	}

	public javax.swing.JButton getBtnCancelar() {
		return btnCancelar;
	}
}
